package com.ce.pms.renovation.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.ce.pms.base.service.impl.PmsBaseServiceImpl;
import com.ce.pms.charge.service.IParameterDefService;
import com.ce.pms.charge.vo.ParameterDefVO;
import com.ce.pms.common.dao.IOrganizationalStructureDao;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.service.ICodingGeneratorService;
import com.ce.pms.common.util.UpLoadFile;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.dao.IImageDao;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.house.model.ImageDomain;
import com.ce.pms.house.service.IHouseService;
import com.ce.pms.house.service.IImageService;
import com.ce.pms.house.vo.FlatVO;
import com.ce.pms.house.vo.ImageVO;
import com.ce.pms.renovation.dao.IPassDao;
import com.ce.pms.renovation.dao.IRenovateLicenceDao;
import com.ce.pms.renovation.dao.IRenovateRequisitionDao;
import com.ce.pms.renovation.model.PassChargeItemDO;
import com.ce.pms.renovation.model.PassDO;
import com.ce.pms.renovation.model.RenovateLicenceDO;
import com.ce.pms.renovation.model.RenovateRequisitionDO;
import com.ce.pms.renovation.service.ICertificateManageService;
import com.ce.pms.renovation.service.IRenovateChargeService;
import com.ce.pms.renovation.service.IRenovateSupervisionService;
import com.ce.pms.renovation.vo.AbstractViolationVO;
import com.ce.pms.renovation.vo.LicenceListVO;
import com.ce.pms.renovation.vo.LicenceQueryVO;
import com.ce.pms.renovation.vo.PassVO;
import com.ce.pms.renovation.vo.RenovateLicenceVO;
import com.ce.util.BeanUtil;
import com.sitechasia.webx.core.support.Page;

/**
 * 证件管理服务类
 */
public class CertificateManageServiceImpl extends PmsBaseServiceImpl implements ICertificateManageService{
	private ICodingGeneratorService codingGeneratorService;
	private IHouseService houseService;
	private IImageDao imageDao;
	private IImageService imageService;
	private IOrganizationalStructureDao organizationalStructureDao;
	private IParameterDefService parameterDefService;
	private IPassDao passDao;
	private IRenovateChargeService renovateChargeService;
	private IRenovateLicenceDao renovateLicenceDao;
	private IRenovateRequisitionDao renovateRequisitionDao;
	private IRenovateSupervisionService renovateSupervisionService;

   /**
    * 功能描述:增加出入证<br>
    * 在增加出入证时，同时将根据出入证的收费项目配置向非常规费用表抛帐；<br>
    * @param passVO
    * @return<br>
    * Create author:罗军林<br>
    * Create on:2008-12-29<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public PassVO addPass(PassVO passVO){
	   checkLicenceId(passVO.getRenovateLicenceId());
	   checkParameterIsNull(passVO.getPassNumber(), "renovate:renovate_pass_number_not_null");
	   checkCreatorInfo(passVO.getCreateId());

	   PassDO passDo=new PassDO();
	   assemblePassV2D(passVO,passDo);
	   if( null!=passVO.getPhotoVo() ){
		   addImage(passVO, passDo);
	   }
	   passDo.setSysInfo(this.createInfo(passVO.getCreateId()));
	   passDo.setChargeFeeState(SysrefcodeDO.RM_FEE_STATE_NO);;
	   passDo.setReturnYn(SysrefcodeDO.CONSTANTS_DIGITAL_ZERO);
	   passDo.setRenovateLicence( renovateLicenceDao.findById(passVO.getRenovateLicenceId()) );
	   passDo=passDao.saveObject(passDo);

	   notifyAddPass(passDo.getKeyword());

	   return assemblePassD2V(passDo);
   }

   /**
    * 功能描述:删除出入证<br>
    * @param passId<br>
    * Create author:罗军林<br>
    * Create on:2008-12-29<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public void deletePass(Long passId){
	   checkPassId(passId);
	   isAllowDeleteOrEditPass(passId);

	   renovateChargeService.deletePassChargeItem(passId);
	   passDao.deleteObjectById(passId);
   }

   /**
    * 功能描述:修改出入证<br>
    * @param passVO
    * @return<br>
    * Create author:罗军林<br>
    * Create on:2008-12-29<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public PassVO editPass(PassVO passVO){
	   checkPassId(passVO.getKeyword());

	   PassDO passDo=passDao.findById(passVO.getKeyword());
	   //对图片进行操作
	   ImageDomain photo = passDo.getPhoto();
	   if( isDeleteImage(passVO.getPhotoVo(), photo) ){
		   deleteImage(passDo, photo);
	   }else if(isDeleteAndAddImage(passVO.getPhotoVo(), photo)){
		   deleteImage(passDo, photo);
		   addImage(passVO,passDo);
	   }else if( isAddImage(passVO.getPhotoVo(), photo)){
		   addImage(passVO, passDo);
	   }

	   assemblePassV2D(passVO,passDo);

	   return assemblePassD2V(passDo);
   }

   /**
    * 功能描述:生成出入证号<br>
    * @return<br>
    * Create author:罗军林<br>
    * Create on:2009-1-6<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public String generatePassNumber(){
	   return codingGeneratorService.generatePassNumber();
   }

    /**
	 * 功能描述:查询指定许可证的出入证列表（未收的将不查出）<br>
	 * @param licenceId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public List<PassVO> getChargePasses(Long licenceId) {
		checkLicenceId(licenceId);
		List<PassVO> temp = getPasses(licenceId);

		Iterator<PassVO> iter = temp.iterator();
		while (iter.hasNext()) {
			PassVO item = iter.next();
			if (SysrefcodeDO.RM_FEE_STATE_NO.equals(item.getChargeFeeState())) {
				iter.remove();
			}
		}
		return temp;
	}

   /**
    * 功能描述:查询许可证<br>
    * @param renovateRequisitionId
    * @return<br>
    * Create author:罗军林<br>
    * Create on:2008-12-25<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public RenovateLicenceVO getLicence(Long renovateRequisitionId){
	   RenovateLicenceDO renvoateLicence=renovateLicenceDao.getRenovateLicenceByRequisitionID(
			   renovateRequisitionId);
	   return renvoateLicence==null ? null : assembleLicenceD2V(renvoateLicence);
   }

   /**
    * 功能描述:查询指定许可证的详细信息<br>
    * @param renovateRequisitionId
    * @return<br>
    * Create author:罗军林<br>
    * Create on:2008-12-25<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public RenovateLicenceVO getLicenceByLicenceId(Long licenceId){
	   RenovateLicenceDO renvoateLicence=renovateLicenceDao.findById(licenceId);
	   return assembleLicenceD2V(renvoateLicence);
   }


   /**
    * 功能描述:取得出入证详细信息<br>
    * @param passVO
    * @return<br>
    * Create author:罗军林<br>
    * Create on:2008-12-29<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public PassVO getPass(Long passId){
	   checkPassId(passId);

	   PassDO passDo=passDao.findById(passId);

	   return assemblePassD2V(passDo);
   }


   /**
	 * 功能描述:查询指定许可证的所有出入证列表<br>
	 * @param licenceId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public List<PassVO> getPasses(Long licenceId) {
		checkLicenceId(licenceId);
		List<PassDO> passDOList = renovateLicenceDao.getPasses(licenceId);
		return assemblePassListD2V(passDOList);
	}

    /**
	 * 功能描述:是否允许编辑或删除许可证<br>
	 * @param licenceId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Boolean isAllowDeleteOrEditPass(Long passId) {
		PassDO passDo = passDao.findById(passId);
		if (SysrefcodeDO.RM_FEE_STATE_IN.equals(passDo.getChargeFeeState())) {
			throw new BusinessException("renovate:renovate_delete_charge_fail",BusinessException.ERROR);
		}
		return true;
	}

    /**
	 * 功能描述:许可证查询<br>
	 * @param licenceQueryVO
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@SuppressWarnings("unchecked")
	public Page queryLicences(LicenceQueryVO licenceQueryVO) {
		Page page = renovateLicenceDao.queryLicences(licenceQueryVO);
		List<LicenceListVO> result = page.getResult();
		for (LicenceListVO item : result) {
			SysrefcodeDO licenceState = sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.RM_RENOVATE_LICENCE_STATE_CODE,
					item.getRenovateLicenceState());
			item.setRenovateLicenceStateView(licenceState.getName());
		}
		return page;
	}

   /**
    * 功能描述:归还出入证<br>
    * @param passMap key 出入证id,value 费用状态<br>
    * 如果是退证，将向费用记录表中增加一条退证的记录
    * Create author:罗军林<br>
    * Create on:2008-12-29<br>
    * Edit author:<br>
    * Edit on:<br>
    * Why:<br>
    */
   public void returnPass(Map<Long, String> passMap){
	   checkParameterIsNull(passMap, "没有归还任何出入证");
	   for(Long passId : passMap.keySet()){
		   PassDO passDo=passDao.findById(passId);
		   passDo.setReturnYn(passMap.get(passId));
		   if( SysrefcodeDO.CONSTANTS_DIGITAL_ONE.equals(passDo.getReturnYn())){
			   renovateChargeService.notifyReturnPassCharge(passId);
		   }else{
			   renovateChargeService.deletePassChargeRecord(passId);
		   }
	   }
   }


   public void setCodingGeneratorService(
		ICodingGeneratorService codingGeneratorService) {
	this.codingGeneratorService = codingGeneratorService;
}


	/**
	    * 功能描述:办理许可证<br>
	    * 1)如果keyword为null，则认为是刚办理，否则认为是修改<br>
	    * 2）当已经产生了违规记录或出入证，许可证发放状态不能修改<br>
	    * 3）许可证发放，申请状态改为监管<br>
	    * 4）未发放，申请状态则改为新建<br>
	    * 5)修改房屋状态
	    * @param licenceVO
	    * @return<br>
	    * Create author:罗军林<br>
	    * Create on:2008-12-26<br>
	    * Edit author:<br>
	    * Edit on:<br>
	    * Why:<br>
	    */
	   public RenovateLicenceVO transactLicence(RenovateLicenceVO licenceVO){
		   RenovateLicenceDO licence=null;
		   if(null==licenceVO.getKeyword()){
			   licence = addLicence(licenceVO);
		   }else{
			   licence = editLicence(licenceVO);
		   }

		   if( SysrefcodeDO.RM_RENOVATE_LICENCE_STATE_OK.equals(licence.getState())){
			   if(SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_ADD.equals(licence.getRenovateRequisition().getProcessState())){
				   licence.getRenovateRequisition().setProcessState(SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_SUP);
				   houseService.notifyHouseRenovationInAction(licence.getRenovateRequisition().getHouse().getKeyword());
			   }
		   }else{
			   checkHasPass(licence.getKeyword());
			   checkHasViolation(licence.getKeyword());
			   licence.getRenovateRequisition().setProcessState(SysrefcodeDO.RM_RENOVATE_PROCESS_STATE_ADD);
			   houseService.notifyHouseRenovationOutAction(licence.getRenovateRequisition().getHouse().getKeyword());
		   }
		   return assembleLicenceD2V(licence);
	   }

  /**
 * 功能描述:增加图片<br>
 * @param passVO
 * @param passDo<br>
 * Create author:罗军林<br>
 * Create on:2009-1-6<br>
 * Edit author:<br>
 * Edit on:<br>
 * Why:<br>
 */
private void addImage(PassVO passVO, PassDO passDo) {
	passVO.getPhotoVo().setId(null);
	Long imageId= imageService.addImage(passVO.getPhotoVo());
	passDo.setPhoto(imageId==null ? null : imageDao.findById(imageId));
}

	/**
	   * 功能描述:新增许可证<br>
	   * @param licenceVO
	   * @return<br>
	   * Create author:罗军林<br>
	   * Create on:2008-12-26<br>
	   * Edit author:<br>
	   * Edit on:<br>
	   * Why:<br>
	   */
	  private RenovateLicenceDO addLicence(RenovateLicenceVO licenceVO){
		   RenovateLicenceDO renovateLicenceDO=new RenovateLicenceDO();
		   assembleLicenceV2D(licenceVO,renovateLicenceDO);
		   renovateLicenceDO.setTransactDate(this.getDate());
		   renovateLicenceDO.setSysInfo( this.createInfo(licenceVO.getCreator()) );
		   renovateLicenceDao.saveObject(renovateLicenceDO);
		   return renovateLicenceDO;
	  }

	/**
	 * 功能描述:许可证的装配<br>
	 * @param renvoateLicence
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-26<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private RenovateLicenceVO assembleLicenceD2V(RenovateLicenceDO renvoateLicence) {
		RenovateLicenceVO renovateLicenceVO=new RenovateLicenceVO();
		BeanUtil.convertVoAsDo(renvoateLicence, renovateLicenceVO);
		HouseDomain house = renvoateLicence.getRenovateRequisition().getHouse();
		FlatVO flatVO=houseService.getFlatHouseVO(house.getKeyword());
		renovateLicenceVO.setHouseNumber(house.getHouseNumber());
		renovateLicenceVO.setClientNames(renvoateLicence.getRenovateRequisition().getClientNames());
		renovateLicenceVO.setBuildingName(house.getBuilding().getName());
		renovateLicenceVO.setFloor(flatVO.getFloor()==null ? null : flatVO.getFloor().toString() );

		SysrefcodeDO licenceState = sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.RM_RENOVATE_LICENCE_STATE_CODE, renvoateLicence.getState());
		renovateLicenceVO.setRenovateLicenceStateView(licenceState== null ? null : licenceState.getName());

		renovateLicenceVO.setCompanyName(renvoateLicence.getRenovateRequisition().getCompanyName());
		renovateLicenceVO.setBurdenMan(renvoateLicence.getRenovateRequisition().getBurdenMan());
		renovateLicenceVO.setBurdenManPhone(renvoateLicence.getRenovateRequisition().getBurdenManPhone());
		renovateLicenceVO.setFireproofingMan(renvoateLicence.getRenovateRequisition().getFireproofingMan());
		renovateLicenceVO.setItems(renvoateLicence.getRenovateRequisition().getItems());

		renovateLicenceVO.setTransactor(renvoateLicence.getTransactor().getEmployeeName());
		return renovateLicenceVO;
	}

	/**
	 * 功能描述:许可证V2D<br>
	 * @param renovateLicenceVO
	 * @param renovateLicenceDO
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-26<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	  private void assembleLicenceV2D(RenovateLicenceVO renovateLicenceVO,
		   							RenovateLicenceDO renovateLicenceDO){
	   BeanUtil.convertVoAsDo(renovateLicenceVO, renovateLicenceDO);
	   renovateLicenceDO.setTransactor(organizationalStructureDao.findById(renovateLicenceVO.getTransactorId()) );
	   RenovateRequisitionDO renovateRequisitionDO=renovateRequisitionDao.loadById(renovateLicenceVO.getRequisitionId());
	   renovateLicenceDO.setRenovateRequisition(renovateRequisitionDO);
	  }

	/**
	 * 功能描述:出入证的装配<br>
	 * @param item
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private PassVO assemblePassD2V(PassDO item) {
		PassVO temp=new PassVO();
		BeanUtil.convertVoAsDo(item, temp);
		if(null!=item.getPhoto()){
			ImageVO imageVo=new ImageVO();
			BeanUtil.convertVoAsDo(item.getPhoto(), imageVo);
			imageVo.setCreator(item.getPhoto().getSysInfo().getCreator());
			imageVo.setId(item.getPhoto().getKeyword());
			temp.setPhotoVo(imageVo);
		}
		temp.setReturnState(item.getReturnYn());
		temp.setChargeFeeState(item.getChargeFeeState());
		SysrefcodeDO chargeFeeState=sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.RM_PASS_CHARGE_FEE_STATE_CODE,
				item.getChargeFeeState());
		temp.setChargeFeeStateView(chargeFeeState.getName());
		SysrefcodeDO workType=sysrefcodeDao.getSysrefCodesByCode(
				SysrefcodeDO.RM_TYPE_OF_WORK_CODE, item.getWorkType());
		temp.setWorkTypeView(workType==null ? null : workType.getName());
		temp.setChargeFeeSum( sumPassItem(renovateLicenceDao.getPassChargeItemDOs(item.getKeyword())) );
		temp.setReturnSum( sumReturnPassItem(renovateLicenceDao.getPassChargeItemDOs(item.getKeyword())) );
		SysrefcodeDO returnFeeState = sysrefcodeDao.getSysrefCodesByCode(SysrefcodeDO.RM_PASS_RETURN_FEE_STATE_CODE, item.getReturnFeeState());
		temp.setReturnFeeStateView(returnFeeState == null ? null : returnFeeState.getName());//退费状态显示值

		return temp;
	}

	/**
     * 功能描述:许可证列表的装配<br>
	 * @param passDOList
	 * @return <br>
	 * Create author:罗军林<br>
	 * Create on:2008-12-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private List<PassVO> assemblePassListD2V(List<PassDO> passDOList) {
		List<PassVO> passVOList=new ArrayList<PassVO>();
		   for(PassDO item : passDOList){
			   passVOList.add( assemblePassD2V(item) );
		   }
		return passVOList;
	}



	/**
	 * 功能描述:功能描述:许可证的装配<br>
	 * @param passVO
	 * @param passDO<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-15<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void assemblePassV2D(PassVO passVO, PassDO passDO){
		   BeanUtil.convertVoAsDo(passVO, passDO);
	}

	/**
	 * 功能描述:检查是否有违记录，如果有将抛出异常<br>
	 * @param licence<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkHasViolation(Long licenceId) {
		List<AbstractViolationVO>  violationList = renovateSupervisionService.getViolationsByLicenceId(licenceId);
		   if(violationList!=null && violationList.size()>0){
			   throw new BusinessException("renovate:renovate_licence_not_edit",BusinessException.ERROR);
		   }
	}

	/**
	 * 功能描述:检查是否有出入证，如果有将抛出异常<br>
	 * @param licence<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-8<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkHasPass(Long licenceId) {
		List<PassVO> passes=getPasses(licenceId);
		   if(passes!=null && passes.size()>0){
			   throw new BusinessException("renovate:renovate_has_pass",BusinessException.ERROR);
		   }
	}

	/**
	 * 功能描述:检查许可证ID是否为空，如果为空将抛出异常<br>
	 * @param passVO<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkLicenceId(Long licenceid) {
		checkParameterIsNull(licenceid, "renovate:renovate_licence_id_not_null");
	}

    /**
	 * 功能描述:检查出入证ID是否为空，如果是则抛出异常<br>
	 * @param passId<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-15<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void checkPassId(Long passId) {
		checkParameterIsNull(passId, "renovate:renovate_pass_id_not_null");
	}

	  /**
	 * 功能描述:删除图片<br>
	 * @param passDo
	 * @param photo<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void deleteImage(PassDO passDo, ImageDomain photo) {
		UpLoadFile.deleteFile(photo.getPath(), photo.getName());
		imageService.deleteImageByID(photo.getKeyword());
		passDo.setPhoto(null);
	}

	  /**
	   * 功能描述:修改许可证<br>
	   * @param licenceVO
	   * @return<br>
	   * Create author:罗军林<br>
	   * Create on:2008-12-26<br>
	   * Edit author:<br>
	   * Edit on:<br>
	   * Why:<br>
	   */
	  private RenovateLicenceDO editLicence(RenovateLicenceVO licenceVO){
		   RenovateLicenceDO renovateLicenceDO=renovateLicenceDao.findById(licenceVO.getKeyword());
		   if(SysrefcodeDO.RM_RENOVATE_LICENCE_STATE_OK.equals(licenceVO.getState())){
			   isAllowTransact(renovateLicenceDO.getRenovateRequisition());
		   }
		   assembleLicenceV2D(licenceVO,renovateLicenceDO);
		   return renovateLicenceDO;
	  }

	  /**
	 * 功能描述:如果之没有图片，但这次添加了图片将返回true<br>
	 * @param phothVo
	 * @param photoDo
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isAddImage(ImageVO phothVo, ImageDomain photo) {
		return phothVo!=null && photo==null;
	}

	/**
	   * 功能描述:是否允许发放许可证<br>
	   * @param renovateRequisition
	   * @return<br>
	   * Create author:罗军林<br>
	   * Create on:2008-12-26<br>
	   * Edit author:<br>
	   * Edit on:<br>
	   * Why:<br>
	   */
	  private boolean isAllowTransact(RenovateRequisitionDO renovateRequisition){
		   if( SysrefcodeDO.RM_FEE_STATE_NO.equals( renovateRequisition.getFeeState())
				   || ! SysrefcodeDO.RM_RENOVATE_REQUISITION_STATE_PASS.equals(renovateRequisition.getRequisitionState()) ){
			   throw new BusinessException("renovate:renovate_must_charge_pass");
		   }
		   return true;
	  }

	/**
	 * 功能描述:如果之前有图片，但将其删除了，并另外添加了一张新图片，将返回true<br>
	 * @param phothVo
	 * @param photoDo
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isDeleteAndAddImage(ImageVO phothVo, ImageDomain photoDo) {
		return null!=phothVo && phothVo.getId()!=null && photoDo!=null && !phothVo.getName().equals(photoDo.getName());
	}

	  /**
	 * 功能描述:如果之前有图片，但这次删除了图片将返回true<br>
	 * @param phothVo
	 * @param photoDo
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private boolean isDeleteImage(ImageVO phothVo, ImageDomain photoDo) {
		return null==phothVo && photoDo!=null;
	}

	/**
	   * 功能描述:通知新增出入证<br>
	   * @param passId<br>
	   * Create author:罗军林<br>
	   * Create on:2008-12-29<br>
	   * Edit author:<br>
	   * Edit on:<br>
	   * Why:<br>
	   */
	  private void notifyAddPass(Long passId){
		   renovateChargeService.notifyRegisterPassCharge(passId);
	  }

	/**
	 * 功能描述:对列表的金额进行总和<br>
	 * @param chargeItems
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private BigDecimal sumPassItem(List<PassChargeItemDO> chargeItems){
		BigDecimal temp=BigDecimal.ZERO;
		if( chargeItems==null ){
			return temp;
		}

		for(PassChargeItemDO item : chargeItems){
			temp=temp.add(item.getSum());
		}
		return temp;
	}

	/**
	 * 功能描述:对列表的押金金额进行总和<br>
	 * @param chargeItems
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2009-1-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private BigDecimal sumReturnPassItem(List<PassChargeItemDO> chargeItems){
		BigDecimal temp=BigDecimal.ZERO;
		if( chargeItems==null ){
			return temp;
		}

		for(PassChargeItemDO item : chargeItems){
			ParameterDefVO business= parameterDefService.findParameterDefByPkey(SysrefcodeDO.PARAMETER_DEF_DEPOSIT_CODE);
			checkParameterIsNull(business.getPvalue(), "renovate:renovate_deposit_businessCode_err");

			if(business.getPvalue().equals(item.getItemConfig().getBusinessCode().getKeyword())){
				temp=temp.add(item.getSum());
			}
		}
		return temp;
	}



	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}

	public void setImageDao(IImageDao imageDao) {
		this.imageDao = imageDao;
	}

	public void setImageService(IImageService imageService) {
		this.imageService = imageService;
	}

	public void setOrganizationalStructureDao(IOrganizationalStructureDao organizationalStructureDao) {
		this.organizationalStructureDao = organizationalStructureDao;
	}

	public void setParameterDefService(IParameterDefService parameterDefService) {
		this.parameterDefService = parameterDefService;
	}

	public void setPassDao(IPassDao passDao) {
		this.passDao = passDao;
	}

	public void setRenovateChargeService(IRenovateChargeService renovateChargeService) {
		this.renovateChargeService = renovateChargeService;
	}

	public void setRenovateLicenceDao(IRenovateLicenceDao renovateLicenceDao) {
		this.renovateLicenceDao = renovateLicenceDao;
	}

	public void setRenovateRequisitionDao(IRenovateRequisitionDao renovateRequisitionDao) {
		this.renovateRequisitionDao = renovateRequisitionDao;
	}

	public void setRenovateSupervisionService(IRenovateSupervisionService renovateSupervisionService) {
		this.renovateSupervisionService = renovateSupervisionService;
	}
}
